#!/usr/bin/python
import os, sys, string

# sed '/^$/d' myfile
class XXRemoveBlankLine:
	def __init__(self):
		pass
	
	def printHelp(self, cmd):
		print 'Please use the following cmd:'
		print '    ' + cmd + ' file'
		print 'e.g.'
		print '    ' + cmd + ' /home/fkong/build.xml' 

	def removeblankline(self, file):
		inputfile = file
		outputfile = file + '.0123456789'
		input = open(inputfile, 'r')
		output = open(outputfile, 'w')
		for s in input.xreadlines() :
			if s == "\n" or s == "\r" or s == "\r\n":
				pass
			else:
				output.write(s)
		input.close()
		output.close()
		os.rename(outputfile, inputfile)
	
if len(sys.argv) != 2:
	t = XXRemoveBlankLine()
	t.printHelp(sys.argv[0])
else:
	t = XXRemoveBlankLine()
	t.removeblankline(sys.argv[1])
